#include "stdio.h"
#include "stdlib.h"

#define PAGE_SIZE 256
#define TEST 10

void runtest(int value)
{
	int i, j;
	char test[PAGE_SIZE*5];

	for(i = 0; i < 10; i++)
	{
		for(j = 0; j < PAGE_SIZE*5; j++)
		{
			test[j] = value;
		}
		
		for(j = 0; j < PAGE_SIZE*5; j++)
		{
			if(test[j] != value)
				exit(-3);
		}
	}

	exit(value);
}

int main(int argc, char **argv)
{
	printf("argc: %d\n", argc);
	int j;
	for(j = 0; j < argc; j++)
		printf("argv[%d] = %s\n", j, argv[j]);

	if(argc != 2) return -10;

	if(strcmp("main", argv[1]) == 0)
	{
		printf("Main test starting other tests\n");
		int i;
		int pids[TEST];

		for(i = 0; i < TEST; i++)
		{
			char *args[2];
			char *exe = "exe";
			char buf[5];
			sprintf(buf, "%d", i);

			args[0] = exe;
			args[1] = &buf;

			printf("before exec test %d\n", i);
			pids[i] = exec("andy_test.coff", 2, args);
			printf("test %d running with pid = %d\n", i, pids[i]);
		}

		for(i = 0; i < TEST; i++)
		{
			int status = -1;
			join(pids[i], &status);

			printf("test: %d status: %d\n", i, status);
		}

		return 1;
	}
	else
	{
		int v = atoi(argv[1]);
		runtest(100 + v);
	}

	return 0;
}
